<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%;"
  >
    <el-col :span="20">
      <span>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown trigger="click" @command="handleCommand">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-if="!isRoot" command="del">删除部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item command="edit">编辑部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartmentsApi } from '@/api/departments'
export default {
  props: {
    nodeData: {
      require: true, // 必传属性
      type: Object, // 类型属性
      // default:function(){
      //   return
      // }
      default: () => {} // 默认属性  复杂类型写方法
    },
    isRoot: {
      type: Boolean,
      default: false // 默认属性，简单类型写false
    }

  },
  methods: {
    handleCommand(command) {
      if (command === 'del') {
        this.$confirm('你确认要进行删除么?', '温馨提示').then(async() => {
          // 删除操作成功
          await delDepartmentsApi(this.nodeData.id)
          // 添加提示
          this.$message.success('删除操作成功')
          this.$emit('del-depts')
        }).catch(() => {})
      } else if (command === 'add') {
        this.$emit('add-depts', this.nodeData)
      } else if (command === 'edit') {
        this.$emit('edit-depts', this.nodeData)
      }
    }
  }
}
</script>

<style>

</style>
